package com.itheima.Jiuye09;

public class StudentZuoye implements Comparable<StudentZuoye>{
    private String name;
    private int age;

    public StudentZuoye() {
    }

    public StudentZuoye(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "StudentZuoye{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
//姓名和年龄都相同即认为是同一个学生, 不进行存储
    @Override
    public int compareTo(StudentZuoye o) {
        int a = this.getAge() - o.getAge();
        a=a==0?this.getName().compareTo(o.getName()):a;
        return a;
    }
}
